package tag33_26_08.set;

import java.util.NavigableSet;
import java.util.SortedSet;
import java.util.TreeSet;

public class Set09_TreeSet_ist_Navigable {

	public static void main(String[] args) {

		TreeSet<Integer> basisSet = new TreeSet<Integer>();
		
		basisSet.add(12);
		basisSet.add(12);
		basisSet.add(new Integer(12));
		
		basisSet.add(-17);
		basisSet.add(33);
		
		System.out.println(basisSet); //[-17, 12, 33]
		
		SortedSet<Integer> sortedSet = basisSet;
		NavigableSet<Integer> navSet = basisSet;  // por el grafico de UML

		
		// Celing/floor
		
		Integer x = basisSet.ceiling(0); // gesucht Element >= 0
		System.out.println("ceiling(0) = " + x); 	// 12
		
		x = basisSet.ceiling(12);
		System.out.println("ceiling(12) = " + x); 	// 12
		
		x = basisSet.ceiling(1000);
		System.out.println("ceiling(1000) = " + x); //  null
		
		x = basisSet.floor(1000); // gesucht Element <= 1000
		System.out.println("floor(1000) = " + x); 	//  33
		
		x = basisSet.floor(-17);
		System.out.println("floor(-17) = " + x); 	//  -17
		
		// higher/lower
		x = basisSet.higher(0); // gesucht Element > 0
		System.out.println("higher(0) = " + x); 	//  12
		
		x = basisSet.higher(12); // gesucht Element > 12
		System.out.println("higher(12) = " + x); 	//  33
		
		x = basisSet.lower(-100); // gesucht Element < 0
		System.out.println("lower(-100) = " + x); 	//  null
		
		
		//------------------------------------------------------
		System.out.println("-----------------------------------");
		
		
		x = basisSet.last();
		System.out.println("last() = " + x); 	//  33
		x = basisSet.first();
		System.out.println("first() = " + x); 	//  -17
		
		System.out.println("--------------- gekoppelte (backed) Sets -------------------------------");
		 
		System.out.println(basisSet); //	[-17, 12, 33]
		
		SortedSet<Integer> headSet1 = basisSet.headSet(33); //alle Elemente < 33 ->  
		System.out.println(headSet1); //[-17, 12]
		
		NavigableSet<Integer> headSet2 = basisSet.headSet(33, false);
		System.out.println(headSet2);//[-17, 12]
		
		headSet2 = basisSet.headSet(33, true); //alle Elemente <= 33
		System.out.println(headSet2); //[-17, 12, 33]
		
		System.out.println("-----------------------------------------");
		
		
		SortedSet<Integer> tailSet1 = basisSet.tailSet(-17); // Alle Elemente >= -17
		NavigableSet<Integer> 	tailSet2 = basisSet.tailSet(-17, true); // Alle Elemente >= -17
								tailSet2 = basisSet.tailSet(-17, false);// Alle Elemente > -17
		
		
		System.out.println("------------------------------------------");
		
		// alle Elemente von -17 (inklusiv) bis 33 (exklusiv):
	    SortedSet<Integer> subSet1 = basisSet.subSet(-17, 33);
	    
	    // alle Elemente von -17 (inklusiv) bis 33 (exklusiv):
	    NavigableSet<Integer> subSet2 = basisSet.subSet(-17, true, 33, false);
	    //new TreeSet<Integer>(subSet2); <- Nicht gekoppelt
	    
	    System.out.println("-- Test Subset --");
	    
	    System.out.println(basisSet); //[-17, 12, 33]
	    System.out.println(subSet2);  //[-17, 12]

	    basisSet.add(0);

	    System.out.println(" - basisSet.add(0) ");
	    System.out.println("basisSet: " + basisSet); //[-17, 0, 12, 33]
	    System.out.println("subSet2:  " + subSet2);  //[-17, 0, 12]
	    
	    subSet2.add(19);
	    
	    System.out.println(" - subSet.add(19) ");
	    System.out.println("basisSet: " + basisSet); //[-17, 0, 12, 19, 33]
	    System.out.println("subSet2:  " + subSet2);  //[-17, 0, 12, 19]
		
	    
	    basisSet.add(7000); //OK
//	    subSet2.add(7000);  // Exception! (Grenzen beachten)
	    subSet2.add(-17); //OK
//	    subSet2.add(33);  // Exception! (Grenzen beachten)
	    
	    subSet2 = basisSet.subSet(-17, true, 3000000, false);
	    subSet2.add(8000);  
	    System.out.println(basisSet);
	    System.out.println(subSet2);
	    
			
		
	}// end of main

}
